﻿using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Store.Model.Models;
using Store.Dal;
using Store.Bll;
using Store.ViewModel;
namespace Store.Server.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [EnableCors("any")]
    public class LoginController : ControllerBase
    {
        private readonly EmployeeRegisterBll bll;
        public LoginController(EmployeeRegisterBll bl)
        {
            bll = bl;
        }
        [HttpGet]
        public ObjectResult LoginIndex(string EmployeeAccount, string PassWords)//员工登录
        {
            int i = bll.Login(EmployeeAccount, PassWords);
            return Ok(i);
        }

        [HttpPost]
        public int AddEmployee(Employee emp)//员工添加
        {
            return bll.EmployeeAdd(emp);
        }

        [HttpGet]
        public ObjectResult GetEmployee(string AccountName = null, string Pid = null, int PageIndex = 1, int PageSize = 5)//员工及其角色信息的显示
        {
            int total;
            List<EmployeeModel> data = bll.GetEmployee(AccountName, Pid, PageIndex, PageSize, out total);
            return Ok(new { total = total, data = data });
        }

        [HttpGet]
        public ObjectResult GetMenu()//查询员工权限下的菜单信息
        {
            List<EmployeeMenu> data = bll.GetEmployeeMenus();
            return Ok(data);
        }
        //绑定下拉框
        [HttpGet]
        public ObjectResult GetPoi()
        {
            List<Position> data = bll.GetPositionSelect();
            return Ok(data);
        }
        //角色信息
        [HttpGet]
        public ObjectResult GetPosition(int PageIndex = 1, int PageSize = 5)
        {
            int total;
            List<Position> data = bll.GetPositions(PageIndex, PageSize, out total);
            return Ok(new { total = total, data = data });
        }

        [HttpDelete]
        public int Delete(int id)//修改状态删除
        {
            return bll.DeleteEmployee(id);
        }
        [HttpPut]
        public int Edit(Employee emp)//修改数据
        {
            return bll.EditEmployee(emp);
        }
        //添加角色信息
        [HttpPost]
        public int AddPosition(Position s)
        {
            return bll.AddPositions(s);
        }
        [HttpDelete]
        //删除角色信息
        public int DeletePosition(int id)
        {
            return bll.DeletePositions(id);
        }
        //修改角色信息
        [HttpPut]
        public int EditPosition(Position s)
        {
            return bll.EditPositions(s);
        }


    }
}
